package com.srwl.mytx.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ProgressBar;

import com.srwl.easeui.widget.MyTitleBar;
import com.srwl.mytx.Constant;
import com.srwl.mytx.R;
import com.srwl.mytx.domain.Topic;
import com.srwl.mytx.fragment.TopicFragment;
import com.srwl.mytx.parse.UserProfileManager;

public class SelectForwardTopicActivity extends BaseActivity {
    private TopicFragment topicFragment;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_topic_record);
        MyTitleBar titleBar = findViewById(R.id.title_bar);
        final ProgressBar progressBar = findViewById(R.id.progress_bar);
        titleBar.setTitle("选择跳转主题");
        titleBar.setLeftLayoutClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        topicFragment = TopicFragment.newInstance(2, UserProfileManager.getInstance().getLoginUserInfo().getuId());
        topicFragment.setItemClickListener(new TopicFragment.ItemClickListener() {
            @Override
            public void onItemClick(Topic topic) {
                setResult(RESULT_OK, new Intent().putExtra(Constant.EXTRA_INFO_TOPIC, topic));
                finish();
            }
        });
        topicFragment.setListener(new TopicFragment.InteractionListener() {
            @Override
            public void showLoading(boolean isShowProgressBar) {
                if (isShowProgressBar && !progressBar.isShown()) {
                    progressBar.setVisibility(View.VISIBLE);
                } else if (!isShowProgressBar && progressBar.isShown()) {
                    progressBar.setVisibility(View.GONE);
                }
            }
        });
        getSupportFragmentManager().beginTransaction().add(R.id.fl_container, topicFragment).commit();
    }
}
